package com.ruoyi.leavetime.controller;

import java.text.ParseException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.leavetime.vo.LeaveTimeVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.leavetime.domain.SalaryLeaveTime;
import com.ruoyi.leavetime.service.ISalaryLeaveTimeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 请假时间Controller
 * 
 * @author ruoyi
 * @date 2024-08-12
 */
@RestController
@RequestMapping("/leavetime/time")
public class SalaryLeaveTimeController extends BaseController
{
    @Autowired
    private ISalaryLeaveTimeService salaryLeaveTimeService;

    /**
     * 查询请假时间列表
     */
    @PreAuthorize("@ss.hasPermi('leavetime:time:list')")
    @GetMapping("/list")
    public TableDataInfo list(SalaryLeaveTime salaryLeaveTime)
    {
        startPage();
        List<SalaryLeaveTime> list = salaryLeaveTimeService.selectSalaryLeaveTimeList(salaryLeaveTime);
        return getDataTable(list);
    }

    /**
     * 导出请假时间列表
     */
    @PreAuthorize("@ss.hasPermi('leavetime:time:export')")
    @Log(title = "请假时间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SalaryLeaveTime salaryLeaveTime)
    {
        List<SalaryLeaveTime> list = salaryLeaveTimeService.selectSalaryLeaveTimeList(salaryLeaveTime);
        ExcelUtil<SalaryLeaveTime> util = new ExcelUtil<SalaryLeaveTime>(SalaryLeaveTime.class);
        util.exportExcel(response, list, "请假时间数据");
    }

    /**
     * 获取请假时间详细信息
     */
    @PreAuthorize("@ss.hasPermi('leavetime:time:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(salaryLeaveTimeService.selectSalaryLeaveTimeById(id));
    }

    /**
     * 新增请假时间
     */
    @PreAuthorize("@ss.hasPermi('leavetime:time:add')")
    @Log(title = "请假时间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SalaryLeaveTime salaryLeaveTime)
    {
        return toAjax(salaryLeaveTimeService.insertSalaryLeaveTime(salaryLeaveTime));
    }
    @PreAuthorize("@ss.hasPermi('leavetime:time:add')")
    @Log(title = "请假时间", businessType = BusinessType.INSERT)
    @PostMapping("/addleaveTime")
    public void addleaveTime(@RequestBody LeaveTimeVo leaveTimeVo) throws ParseException {
         salaryLeaveTimeService.addLeaveTime(leaveTimeVo);
    }

    /**
     * 修改请假时间
     */
    @PreAuthorize("@ss.hasPermi('leavetime:time:edit')")
    @Log(title = "请假时间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SalaryLeaveTime salaryLeaveTime)
    {
        return toAjax(salaryLeaveTimeService.updateSalaryLeaveTime(salaryLeaveTime));
    }

    /**
     * 删除请假时间
     */
    @PreAuthorize("@ss.hasPermi('leavetime:time:remove')")
    @Log(title = "请假时间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(salaryLeaveTimeService.deleteSalaryLeaveTimeByIds(ids));
    }
}
